View Javadoc
1 /* 2 AntMake 3 4 Copyright (C) 2004 Jose San Leandro Armend?riz 5 jsanleandro@yahoo.es 6 chousz@yahoo.com 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public 10 License as published by the Free Software Foundation; either 11 version 2 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 General Public License for more details. 17 18 You should have received a copy of the GNU General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 Thanks to ACM S.L. for distributing this library under the GPL license. 23 Contact info: jsanleandro@yahoo.es 24 Postal Address: c/Playa de Lagoa, 1 25 Urb. Valdecaba?as 26 Boadilla del monte 27 28660 Madrid 28 Spain 29 30 ****************************************************************************** 31 * 32 * Filename: $RCSfile: MakefileAmTemplateGenerator.java,v $ 33 * 34 * Author: Jose San Leandro Armend?riz 35 * 36 * Description: Is able to generate Makefile.am templates for Java folders. 37 * 38 * Last modified by: $Author: chous $ at $Date: 2004/01/25 20:20:15 $ 39 * 40 * File version: $Revision: 1.2 $ 41 * 42 * Project version: $Name: $ 43 * 44 * $Id: MakefileAmTemplateGenerator.java,v 1.2 2004/01/25 20:20:15 chous Exp $ 45 * 46 */ 47 package org.acmsl.antmake; 48 49 /* 50 * Importing some project-specific classes. 51 */ 52 import org.acmsl.antmake.AntMakeUtils; 53 import org.acmsl.antmake.MakefileAmTemplate; 54 import org.acmsl.antmake.MakefileAmTemplateFactory; 55 56 /* 57 * Importing some ACM-SL Commons classes. 58 */ 59 import org.acmsl.commons.utils.io.FileUtils; 60 61 /* 62 * Importing some Ant classes. 63 */ 64 import org.apache.tools.ant.Project; 65 import org.apache.tools.ant.Task; 66 67 /* 68 * Importing some JDK classes. 69 */ 70 import java.io.File; 71 import java.io.FileNotFoundException; 72 import java.io.IOException; 73 import java.lang.ref.WeakReference; 74 import java.lang.SecurityException; 75 76 /*** 77 * Is able to generate <i>Makefile.am</i> templates for Java folders. 78 * @author <a href="mailto:jsanleandro@yahoo.es" 79 >Jose San Leandro</a> 80 * @version $Revision: 1.2 $ 81 */ 82 public class MakefileAmTemplateGenerator 83 implements MakefileAmTemplateFactory 84 { 85 /*** 86 * Singleton implemented as a weak reference. 87 */ 88 private static WeakReference singleton; 89 90 /*** 91 * Protected constructor to avoid accidental instantiation. 92 */ 93 protected MakefileAmTemplateGenerator() {}; 94 95 /*** 96 * Specifies a new weak reference. 97 * @param generator the generator instance to use. 98 */ 99 protected static void setReference( 100 MakefileAmTemplateGenerator generator) 101 { 102 singleton = new WeakReference(generator); 103 } 104 105 /*** 106 * Retrieves the weak reference. 107 * @return such reference. 108 */ 109 protected static WeakReference getReference() 110 { 111 return singleton; 112 } 113 114 /*** 115 * Retrieves a MakefileAmTemplateGenerator instance. 116 * @return such instance. 117 */ 118 public static MakefileAmTemplateGenerator getInstance() 119 { 120 MakefileAmTemplateGenerator result = null; 121 122 WeakReference reference = getReference(); 123 124 if (reference != null) 125 { 126 result = (MakefileAmTemplateGenerator) reference.get(); 127 } 128 129 if (result == null) 130 { 131 result = new MakefileAmTemplateGenerator() {}; 132 133 setReference(result); 134 } 135 136 return result; 137 } 138 139 /*** 140 * Generates a <i>Makefile.am</i> template for given Java package. 141 * @param projectName the project name.b 142 * @param packageName the package name. 143 * @return a template of such kind. 144 */ 145 public MakefileAmTemplate createMakefileAmTemplate( 146 String projectName, String packageName) 147 { 148 MakefileAmTemplate result = null; 149 150 if ( (projectName != null) 151 && (packageName != null)) 152 { 153 result = 154 new MakefileAmTemplate( 155 projectName, packageName) {}; 156 } 157 158 return result; 159 } 160 161 /*** 162 * Writes a Java folder's <i>Makefile.am</i> file to disk. 163 * @param template the template to write. 164 * @param outputDir the output folder. 165 * @param task the task (for logging purposes). 166 * @throws AntMakeException if the file cannot be created. 167 */ 168 public void write( 169 MakefileAmTemplate template, 170 File outputDir, 171 Task task) 172 throws AntMakeException 173 { 174 if ( (template != null) 175 && (outputDir != null)) 176 { 177 FileUtils t_FileUtils = FileUtils.getInstance(); 178 179 AntMakeUtils t_AntMakeUtils = AntMakeUtils.getInstance(); 180 181 if ( (t_FileUtils != null) 182 && (t_AntMakeUtils != null)) 183 { 184 try 185 { 186 t_AntMakeUtils.log( 187 task, 188 "Writing " 189 + outputDir.getAbsolutePath() 190 + File.separator 191 + t_AntMakeUtils.toRelativeFolder(template.getPackageName()) 192 + File.separator 193 + "Makefile.am", 194 Project.MSG_VERBOSE); 195 196 t_FileUtils.writeFile( 197 outputDir.getAbsolutePath() 198 + File.separator 199 + t_AntMakeUtils.toRelativeFolder(template.getPackageName()) 200 + File.separator 201 + "Makefile.am", 202 template.toString()); 203 } 204 catch (FileNotFoundException fileNotFoundException) 205 { 206 throw new AntMakeException( 207 "cannot write Makefile.am", 208 fileNotFoundException); 209 } 210 catch (SecurityException securityException) 211 { 212 throw new AntMakeException( 213 "cannot write Makefile.am", 214 securityException); 215 } 216 catch (IOException ioException) 217 { 218 throw new AntMakeException( 219 "cannot write Makefile.am", 220 ioException); 221 } 222 } 223 } 224 } 225 }

This page was automatically generated by Maven